package com.example.xd.mvp_project.utils;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.Set;

/**
 * @auther XuDan on 2018/10/16.
 */
public class SpUtils {
    private static final String SHARED_NAME = "mvp_project";

    public static void putBoolean(Context ctx, String key, boolean value) {
        SharedPreferences sp = ctx.getSharedPreferences(SHARED_NAME,
                Context.MODE_PRIVATE);
        sp.edit().putBoolean(key, value).commit();
    }

    public static boolean getBoolean(Context ctx, String key, boolean defValue) {
        SharedPreferences sp = ctx.getSharedPreferences(SHARED_NAME,
                Context.MODE_PRIVATE);
        return sp.getBoolean(key, defValue);
    }

    public static void putString(Context ctx, String key, String value) {
        SharedPreferences sp = ctx.getSharedPreferences(SHARED_NAME,
                Context.MODE_PRIVATE);
        sp.edit().putString(key, value).commit();
    }

    public static String getString(Context ctx, String key, String defValue) {
        SharedPreferences sp = ctx.getSharedPreferences(SHARED_NAME,
                Context.MODE_PRIVATE);
        return sp.getString(key, defValue);
    }

    public static void putInt(Context ctx, String key, int value) {
        SharedPreferences sp = ctx.getSharedPreferences(SHARED_NAME,
                Context.MODE_PRIVATE);
        sp.edit().putInt(key, value).commit();
    }

    public static void putLong(Context ctx, String key, long value) {
        SharedPreferences sp = ctx.getSharedPreferences(SHARED_NAME,
                Context.MODE_PRIVATE);
        sp.edit().putLong(key, value).commit();
    }

    public static int getInt(Context ctx, String key, int defValue) {
        SharedPreferences sp = ctx.getSharedPreferences(SHARED_NAME,
                Context.MODE_PRIVATE);
        return sp.getInt(key, defValue);
    }

    public static long getLong(Context ctx, String key, long defValue) {
        SharedPreferences sp = ctx.getSharedPreferences(SHARED_NAME,
                Context.MODE_PRIVATE);
        return sp.getLong(key, defValue);
    }

    public static void putStringSet(Context ctx, String key, Set<String> values) {
        SharedPreferences sp = ctx.getSharedPreferences(SHARED_NAME,
                Context.MODE_PRIVATE);
        sp.edit().putStringSet(key, values).commit();
    }

    public static Set<String> getStringSet(Context ctx, String key, Set<String> defValue) {
        SharedPreferences sp = ctx.getSharedPreferences(SHARED_NAME,
                Context.MODE_PRIVATE);
        return sp.getStringSet(key, defValue);
    }
}
